<!--
 * @Author: gaotang
 * @Date: 2025年01月03日
 * @Email: qq23745038@126.com
 * @LastEditors: gaotang
 * @LastEditTime: 2025-01-03 18:54:52
-->
<template>
  <Echart v-if="pageflag" :options="options" class="left_center_inner" ref="charts" height="300px" isClick
    @chartClick="chartClick" />
  <Reacquire v-else @onclick="getData" style="line-height: 300px">
    重新获取
  </Reacquire>
</template>

<script>
import { colorsA, colorsB, legend, xAxis, yAxis } from '@/config/EChartVar';
import { graphic } from 'echarts';

export default {
  name: 'ACenterTopLeft',
  data() {
    return {
      options: {},
      countUserNumData: {
        axisData: ['', '8月', '9月', '10月', '11月', '12月', ''],
        seriesData: [0, 21.3, 20.4, 19.8, 24.6, 17.5, 0],
        seriesDataBg: [0, 50, 30, 20, 70, 30, 0],
      },
      pageflag: true,
      timer: null,
    };
  },
  created() {
    this.getData();
  },
  mounted() { },
  beforeDestroy() {
    this.clearData();
  },
  methods: {
    chartClick(params) {
      // 这里处理你的点击逻辑
      this.$emit('chartClick', params);
    },
    clearData() {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
    },
    getData() {
      this.pageflag = true;
      this.init(this.countUserNumData);
    },
    //轮询
    switper() {
      if (this.timer) {
        return;
      }
      let looper = (a) => {
        this.getData();
      };
      this.timer = setInterval(
        looper,
        2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
      );
      let myChart = this.$refs.charts.chart;
      myChart.on('mouseover', (params) => {
        this.clearData();
      });
      myChart.on('mouseout', (params) => {
        this.timer = setInterval(
          looper,
          2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
        );
      });
    },
    init(currentData) {
      let axisData = currentData.axisData;
      let seriesData = [
        [...currentData.seriesData],
        [...currentData.seriesDataBg],
      ];
      const options = {
        grid: {
          top: '15%',
          left: '4%',
          right: '6%',
          bottom: '12%',
          containLabel: true,
        },
        legend: {
          show: true,
          top: '4%',
          right: '4%',
          icon: 'circle',
          itemWidth: 12,
          itemHeight: 12,
          // itemGap: 60,
          textStyle: legend.textStyle,
          data: ['万辆'],
        },
        xAxis: {
          type: 'category',
          data: axisData,
          boundaryGap: false,
          splitLine: {
            show: false,
          },
          axisTick: {
            show: false, // 不显示下切线
          },
          axisLabel: xAxis.axisLabel,
          axisLine: {
            lineStyle: {
              background: 'rgba(176, 215, 255, 0.4)',
            },
          },
        },
        yAxis: [
          {
            type: 'value',
            // max: 8000,
            // min: 100,//
            // interval: 2000,
            axisLabel: yAxis.axisLabel,
            axisLine: {
              show: false,
              // interval: 1,
              lineStyle: {
                color: 'rgba(0,0,0,0.5)',
              },
            },
            splitLine: {
              show: true,
              // interval: 1,
              lineStyle: {
                color: ['rgba(176, 215, 255, 0.2)'],
                width: 1,
                type: 'dashed',
              },
            },
            // splitLine: {
            //   show: false,
            // },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [],
      };
      const series = [
        {
          name: '万辆',
          type: 'line',
          // 动画配置
          animation: true,
          animationDuration: 2000,
          animationEasing: 'quarticInOut',
          animationDelay: function (idx) {
            return idx * 150;
          },
          smooth: false,
          showSymbol: false,
          data: seriesData[0],
          itemStyle: {
            normal: {
              color: '#287CE8',
              // color: 'rgba(0,219,254, .7)',
            },
          },
          areaStyle: {
            color: colorsB[1],
          },
          lineStyle: {
            normal: {
              width: 2,
            },
          },
          label: {
            show: false,
          },
          markPoint: {
            symbol: 'circle',
            symbolSize: [14, 14], // 容器大小
            symbolOffset: ['0%', '0%'],
            data: [
              {
                name: '最大值',
                type: 'max',
                valueIndex: 1,
              },
            ],
            label: {
              show: true,
              position: 'top',
              fontSize: 12,
              color: '#287CE8',
              formatter: (par) => {
                return par.value + '';
              },
            },
          },
        },
      ];
      options.series = series;
      this.options = options;
    },
  },
};
</script>
<style lang="scss" scoped></style>
